package com.itxx.anonymousAndLambda.test6;

import java.util.Random;

//  接口抽象 方法 带有 参数  和 返回值类型
public interface EatAble {
    String eat(int week);
}

class Test {
    public static void main(String[] args) {
        //匿名内部类
        useEatAble(new EatAble() {
            @Override
            public String eat(int week) {
                if (week >= 1 && week <= 5) {
                    return "(匿名内部类)吃米饭";
                }
                return "(匿名内部类)下馆子";
            }
        });
        //lambda表达式
        useEatAble((int week) -> {
            if (week >= 1 && week <= 5) {
                return "(lambda表达式)吃米饭";
            }
            return "(lambda表达式)下馆子";
        });

    }

    public static void useEatAble(EatAble eatAble) {
        Random r = new Random();
        int week = r.nextInt(6) + 1;
        String food = eatAble.eat(week);
        System.out.println("今天是星期" + week + "吃" + food);
    }
}
